package com.webermagem.DAO;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.Transaction;

import com.webermagem.util.HibernateUtil;

public abstract class GenericDAO{
		
		public void save(Object objeto) {
			Session session = HibernateUtil.getSessionFactory().openSession();
			Transaction t = session.beginTransaction();
			session.save(objeto);
			t.commit();
		}
		public Object getByID(long id, Object objeto) {
			Session session = HibernateUtil.getSessionFactory().openSession();
			return  session.load(objeto.getClass(), id);
		}
		public List<?> list(String parametroQuery) {
			Session session = HibernateUtil.getSessionFactory().openSession();
			Transaction t = session.beginTransaction();
			List lista = session.createQuery(parametroQuery).list();
			t.commit();
			return lista;
		}
		public void remove(Object objeto) {
			Session session = HibernateUtil.getSessionFactory().openSession();
			Transaction t = session.beginTransaction();
			session.delete(objeto);
			t.commit();
		}
		public void update(Object objeto) {
			Session session = HibernateUtil.getSessionFactory().openSession();
			Transaction t = session.beginTransaction();
			session.update(objeto);
			t.commit();
		}

}
